package com.xjj.datarources.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjj.datarources.base.DataSources;
import com.xjj.datarources.common.ResultVo;
import com.xjj.datarources.service.DataSourceService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @name: xjj
 * @date: 2021/5/31 13:17
 */


@Controller
@RequestMapping("datasource")
public class DataSourceController {


    @Resource
    private DataSourceService dataSourceService;



    @PostMapping("/addDataResource")
    @RequiresPermissions("datasource:edit")
    @ResponseBody
    public Integer addDataResource(@Validated DataSources dataSources){


        return dataSourceService.add(dataSources);
    }

    @DeleteMapping("/deleteDataResource")
    @RequiresPermissions("datasource:edit")
    @ResponseBody
    public Integer deleteResource(@NotBlank(message = "传入id不能为空") String id){


        return dataSourceService.delete(id);

    }


    @PutMapping("/updateDataResource")
    @RequiresPermissions("datasource:edit")
    @ResponseBody
    public Integer editResource(@Validated DataSources dataSources){

        return dataSourceService.edit(dataSources);
    }

    @GetMapping("/resourceList")
    @RequiresPermissions("datasource:view")
    @ResponseBody
    public List<DataSources> getAllDataSources(){

        return dataSourceService.getAll();
    }


/*    @ResponseBody
    @RequiresPermissions("datasource:view")
    @GetMapping
    public */






}
